<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml" xmlns:shiro="http://www.w3.org/1999/xhtml">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-left">
                        <!--<button shiro:hasPermission="jzweb:testFeedback:add" type="button" class="btn  btn-primary"
                                onclick="add()">
                            <i class="fa fa-plus" aria-hidden="true"></i>添加
                        </button>-->
                        <button shiro:hasPermission="jzweb:dispatch:batchRemove" type="button"
                                class="btn  btn-danger"
                                onclick="batchRemove()">
                            <i class="fa fa-trash" aria-hidden="true"></i>删除
                        </button>
                    </div>
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="reLoad()">查询</button>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="eBatchId1" name="ebatchId" class="form-control" >
                        </select>
                    </div>

                    <div class="columns pull-left" style="margin-left: 5px; margin-right: 5px">
                        <button type="button" class="btn  btn-success" shiro:hasPermission="jzweb:dispatch:import"
                                onclick="downExcelModel('/synthesize/dispatch/download')">
                            <i class="fa fa-download" aria-hidden="true"></i>下载导入模板
                        </button>
                    </div>
                    <div class="columns pull-left col-md-1 nopadding">
                        <select id="eBatchId" name="eBatchId" class="form-control" >
                        </select>
                    </div>
                    <div class="columns pull-left" style="margin-left:4px">
                        <form shiro:hasPermission="jzweb:dispatch:import" id="importExcelForm" method="post"
                              enctype="multipart/form-data">
                            <input class="form-control" style="width:200px" name="feedbackFiles" id="feedbackFiles" type="file">
                        </form>
                    </div>
                    <div class="columns pull-left" style="margin-left:4px">
                        <button shiro:hasPermission="jzweb:dispatch:import" type="button"
                                class="btn  btn-success"
                                onclick="importExcel($('#feedbackFiles'),$('#importExcelForm'),$('#eBatchId').val(),'/synthesize/dispatch/import')">
                            <i class="fa fa-upload" aria-hidden="true"></i>导入
                        </button>
                    </div>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">
                </table>
            </div>
        </div>
    </div>
</div>
<!--shiro控制bootstraptable行内按钮看见性 -->
<div>
    <script type="text/javascript">
        var s_edit_h = 'hidden';
        var s_remove_h = 'hidden';
        var s_resetPwd_h = 'hidden';
    </script>
</div>
<div shiro:hasPermission="jzweb:dispatch:remove">
    <script type="text/javascript">
        var s_remove_h = '';
    </script>
</div>
<div shiro:hasPermission="jzweb:dispatch:edit">
    <script type="text/javascript">
        s_edit_h = '';
    </script>
</div>

<div shiro:hasPermission="jzweb:dispatch:resetPwd">
    <script type="text/javascript">
        var s_resetPwd_h = '';
    </script>
</div>
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript" src="/js/webJs/synthesizeWeb/dispatch/dispatch.js"></script>
<script type="text/javascript" src="/js/jquery-form.js"></script>

<script>

    $(function () {

        $.ajax({
            url:'/synthesize/dispatch/eBatch',
            success:function (r) {
                console.log("r = " ,r);
                if (r.code == 0){
                    var list = r.data;
                    var opt = '<option value="">请选择考试批次</option>';
                    var a = '';
                    for (var i = 0; i < list.length; i++) {
                        if (list[i].type==0){
                            a = "理论考试"
                        }
                        if (list[i].type==1){
                            a = "技能考试"
                        }
                        if (list[i].type==2){
                            a = "社会实践"
                        }
                        opt += '<option value="' + list[i].id + '">' + list[i].name +'('+ a + ')</option>'
                    }
                    $("#eBatchId").html(opt);
                    $("#eBatchId1").html(opt);
                }else {
                    layer.msg(r.msg);
                }
            }
        })
    })

    //导入
    function importExcel(fileObj, formObj,eBatchId,url) {
        if (eBatchId==null||eBatchId==''){
            layer.msg('请选择考试批次后导入!');
        }else {
            var fileUrl = fileObj.val();
            var suffix = fileUrl.substr(fileUrl.lastIndexOf(".")).toLowerCase();//获得文件后缀名
            if (suffix == '.xls' || suffix == '.xlsx') {
                if (fileUrl) {
                    formObj.ajaxSubmit({
                        type: "post",
                        url: url,
                        data: {eBatchId: eBatchId},
                        dataType: "json",
                        success: function (data) {
                            console.log("data",data);
                            if (data.code == 0) {
                                layer.msg('导入成功 !');
                                $('#exampleTable').bootstrapTable('refresh');
                            } else if (data.code ==41304 ) {
                                layer.confirm('是否下载错误报告？', {
                                    btn1:function(index){
                                        window.location.href = '/synthesize/dispatch/importError';
                                        layer.close(index)
                                    }
                                });
                            } else{
                                layer.msg(data.msg);
                            }
                        }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                            console.log(XMLHttpRequest, textStatus, errorThrown)
                            layer.msg('出错了!');
                        }
                    });
                } else {
                    layer.msg('上传的文件不可为空');
                    // parent.$.messager.alert('警告', "上传的文件不可为空", 'warning');
                }
            } else {
                layer.msg('请上传正确的Excel表格!');
                // $.messager.alert('警告', "", 'warning');
            }
        }
    }

</script>

</body>
</html>